import java.util.ArrayList;
import java.util.List;


 // Definition for a binary tree node.
  public class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;

     TreeNode() {
     }

     TreeNode(int val) {
         this.val = val;
     }

     TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
     }
     public List<Integer> preorderTraversal(TreeNode root) {
         List<Integer> root1 = new ArrayList<>();
         if (root == null){
             return null;
         }
         root1.add(root.val);
         int num = 0;
         System.out.println(root1.get(num));//先打印根节点
         num++;
         preorderTraversal(root.left);
         preorderTraversal(root.right);
         return root1;
     }

 }

//class Solution {
//    public List<Integer> preorderTraversal(TreeNode root) {
//        System.out.println()
//    }
//}